package IO.file;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;

public class FileOperation {
    public static void main(String[] args) {
        try {
            Path source = Paths.get("Java/IO/FileOperation.java");
            Path target = Paths.get("demo.java");
            File output = target.toFile();
            if (!output.exists()) {
                output.createNewFile();
            }
            Files.copy(source, target, StandardCopyOption.REPLACE_EXISTING);
            Path newPath = Paths.get("archive.txt");
            Files.move(target, newPath);
            Files.deleteIfExists(newPath);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
